package com.neu.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.neu.entity.Disecategory;
import com.neu.service.DisecategoryService;
import com.neu.util.JsonResult;
import com.neu.util.ResultCode;




@RestController
@CrossOrigin
@RequestMapping("/his/diseCategory")
public class DisecategoryController {
	@Autowired
	private DisecategoryService disecategoryService;
//	获取所有的疾病分类  支持根据分类名称和疾病类型搜索
		@GetMapping("/get_diseCategory")
		public JsonResult<List<Disecategory>> getAllDiseCategory(@RequestParam("dicaName") String dicaName,@RequestParam("dicaType") int dicaType) {
			List<Disecategory> list = disecategoryService.getAllDiseCategory(dicaName,dicaType);
			return new JsonResult<List<Disecategory>>(ResultCode.SUCCESS,list);
		}
//	添加疾病分类的方法
		@PostMapping("/add_diseCategory")
		public JsonResult<Boolean> addDiseCategory(@RequestBody Disecategory disecategory) {
			boolean save = disecategoryService.addDiseCategory(disecategory);
			if(save) {
				return new  JsonResult<Boolean>(ResultCode.SUCCESS,save);
			}else {
				return new JsonResult<Boolean>(ResultCode.INSERT_ERROR,save);
			}
		}	
//  根据id修改
		@PostMapping("/update_diseCategory")
		public JsonResult<Boolean> updateDiseCategory(@RequestBody Disecategory disecategory) {
			boolean upd = disecategoryService.updateDiseCategory(disecategory);
			if(upd){
				return new JsonResult<Boolean>(ResultCode.SUCCESS,upd);
			}else {
				return new JsonResult<Boolean>(ResultCode.UPDATE_ERROR,upd);
			}
		}
//	 分页查询疾病分类  支持分类名称和疾病类型
		@GetMapping("/get_categoryQuery")
		public JsonResult<List<Disecategory>> pageDiseCategoryQuery(int page,int limit,String dicaName,int dicaType) {
			page = (page-1)*limit;
			int total = disecategoryService.pageDiseCategoryTotal(dicaName, dicaType);
			List<Disecategory> list =  disecategoryService.pageDiseCategoryQuery(page,limit,dicaName,dicaType);
			return new JsonResult<List<Disecategory>>(ResultCode.SUCCESS,list,total);
		}
//	删除疾病分类
		@PostMapping("/delere_iseCategory")
		public JsonResult<Boolean> delereDiseCategoryQuery(int id) {
			boolean flag = disecategoryService.delereDiseCategoryQuery(id);
			if(flag) {
				return new JsonResult<Boolean>(ResultCode.SUCCESS,flag);
			}else {
				return new JsonResult<Boolean>(ResultCode.DEL_ERROR,flag);
			}
		}
		
}
